//-----------------------------------------------------------------------
// <copyright file="CountryService.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------	

using System;
using System.Collections;
using MyFramework;
using MIMS.WRS.Entities;
using MIMS.WRS.Data;
    
namespace MIMS.WRS.Business
{   
	/// <summary>
	/// 
	/// </summary> 
    public class CountryService
    {
        #region Country

        public static void CreateCountry(Country country)
        {            
            try
            {
                CountryDAO countryDAO = new CountryDAO();
                countryDAO.CreateCountry(country);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessCreateCountryException, ex);
            }
        }        

        public static void UpdateCountry(Country country)
        {            
            try
            {
                CountryDAO countryDAO = new CountryDAO();
                countryDAO.UpdateCountry(country);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessUpdateCountryException, ex);
            }
        }        

        public static void DeleteCountry(int countryID)
        {            
            try
            {
                CountryDAO countryDAO = new CountryDAO();
                countryDAO.DeleteCountry(countryID);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessDeleteCountryException, ex);
            }
        }
        
        public static Country GetCountry(int countryID)
        {            
            try
            {
                CountryDAO countryDAO = new CountryDAO();
                return countryDAO.GetCountry(countryID);                
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetCountryException, ex);
            }
        }                

		public static CountryCollection GetCountries(CountryColumns orderBy, OrderDirection orderDirection, bool isShowOnCart)
		{            
			try
			{
				CountryCollection countryList = new CountryCollection();
				CountryCollection result = new CountryCollection();
				CountryDAO countryDAO = new CountryDAO();
				
				countryList = countryDAO.GetCountries(orderBy, orderDirection);
				if(isShowOnCart)
				{
					foreach (Country country  in countryList)
					{
						if(country.IsShowOnIDSCart == true)
						{
							result.Add(country);
						}
					}
				}
				else
					result = countryList;

				return result;
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("SR.BusinessGetCountriesException", ex);
			}
		}        


        public static CountryCollection GetCountries(CountryColumns orderBy, OrderDirection orderDirection)
        {            
            try
            {
                CountryDAO countryDAO = new CountryDAO();
                return countryDAO.GetCountries(orderBy, orderDirection);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetCountriesException, ex);
            }
        }        

        public static CountryCollection GetCountries(CountryColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                CountryDAO countryDAO = new CountryDAO();
                return countryDAO.GetCountries(orderBy, orderDirection, page, pageSize, out totalRecords);
            }
            catch (BusinessException)
            {
                throw;
            }
            catch (Exception ex)
            {
                // log this exception
                Logger.Error(ex);
                // wrap it and rethrow
                throw new BusinessException(SR.BusinessGetCountriesException, ex);
            }
        }        


		public static CountryCollection GetCountriesForIDS()
		{            
			try
			{
				CountryDAO countryDAO = new CountryDAO();
				return countryDAO.GetCountriesForIDS();
			}
			catch (BusinessException)
			{
				throw;
			}
			catch (Exception ex)
			{
				// log this exception
				Logger.Error(ex);
				// wrap it and rethrow
				throw new BusinessException("SR.BusinessGetCountriesForIDSException", ex);
			}
		}        

        #endregion
    }
}